package cn.cvs.service.impl;

import cn.cvs.dao.RoomMapper;
import cn.cvs.pojo.Room;
import cn.cvs.service.RoomService;
import cn.cvs.service.UHistoryService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service("roomService")
public class RoomServiceImpl implements RoomService {
    @Resource
    private RoomMapper roomMapper;
    @Override
    public List<Room> getRoomList(String rName,String isSchedule,String isMove) {
        List<Room> roomList = roomMapper.getRoomList(rName, isSchedule, isMove);
        for (Room room : roomList) {
            room.setIsSchedule(getIsScheduleName(room.getIsSchedule()));
            room.setIsMove(room.getIsMove().equals("0")?"未入住":"已入住");
        }
        return roomList;
    }

    @Override
    public int addRoom(Room room) {
        room.setIsMove("0");
        room.setIsSchedule("0");
        return roomMapper.addRoom(room);
    }

    @Override
    public int deleteRoom(Integer rId)
    {
        return roomMapper.deleteRoom(rId);
    }

    @Override
    public Room getRoomByRId(Integer rId) {
        return roomMapper.getRoomByRId(rId);
    }

    @Override
    public int updateRoom(Integer rId) {
        return roomMapper.updateRoom(rId);
    }

    @Override
    public Room getListInfo(String roomNo) {
        return roomMapper.getListInfo(roomNo);
    }

    //处理是否预订的方法
    public String getIsScheduleName(String isSchedule){
        String isScheduleName="";
        switch(isSchedule){
            case "0":
                isScheduleName="预订";
            break;
            case "1":
                isScheduleName="已预订";
            break;
          }
          return isScheduleName;
    }

    public static void main(String[] args) {
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
        RoomService roomService = context.getBean("roomService", RoomService.class);
        List<Room> roomList = roomService.getRoomList("单人房", "0", "0");
        for (Room room : roomList) {
            System.out.println(room);
        }

    }
}
